<?php

/**
 * Created by PhpStorm.
 * User: hjc_0
 * Date: 2016/10/31
 * Time: 20:16
 */
class HsdserverOauthInterf extends UserOauthBaseInterf
{
    private $accountId; //企业账号
    private $sn;    //学号
    private $pwd;  //密码
    private $userType;  //身份类型

    public function callOauthIntf()
    {
        //采用SOAP方式来进行访问的webService,ip:http://172.31.211.97/
        $client = new SoapClient('http://172.31.211.97:8080/amserver.asmx?wsdl');
        $params = array('userName' => $this->sn, 'userPWD' => $this->pwd);
        $strJson = $client->__soapCall('UserLogin', array('parameters' => $params));
        $callResArr = json_decode($strJson->UserLoginResult, true);

        if ($callResArr['code'] != '1000') {
            return array('err_code'=>$callResArr['code'],'err_msg'=>$callResArr['message']);
        }

        $res = $this->doCallBack($callResArr);
        return $res;
    }

    /**
     * 回调操作将用户入库
     * @param array $callRes
     * @throws Exception
     */
    public function doCallBack($callRes)
    {
        $data = array(
            'account_id' => $this->accountId,
            'type' => $this->userType,
            'real_name' => $callRes['name'],
            'number' => $this->sn,
            'status' => 2,
            'sex' => 0,
            'mobile' => $callRes['tel']
        );
        
        $res = $this->addUser($data);
        return $res;
    }
    
    /**
     * 两个对象间复制属性值 ，当一个属性在两边都存在时才复制
     * 属性值是NULL也会复制
     * 
     * @param mixed $src 数据源，数组|对象
     * @param string $des 目标数据
     * @return Object 返回对象本身
     */
    public function setProperties($src)
    {
        $src_vars = is_object($src) ? get_object_vars($src) : $src;
        foreach ($src_vars as $name => $value) {
            if (property_exists($this, $name)) {
                $this->$name = $value;
            }
        }
        
        return $this;
    }
}